package com.zdxf.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.zdxf.domain.UserTokenDO;
import com.zdxf.service.LoginService;
import com.zdxf.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

@Service
public class TestServiceImpl implements LoginService {
    @Autowired
    private RestTemplate restTemplate;

    @Override
    public Result login(Map params) {
        Map dataMap = new HashMap<>();
        dataMap.put("username", params.get("username"));
        dataMap.put("password", params.get("password"));
        HttpEntity httpEntity = new HttpEntity(dataMap);

        ResponseEntity<String> exchange = restTemplate.exchange("http://192.168.10.106/cmda/login/auth", HttpMethod.POST, httpEntity, String.class);
        String body = exchange.getBody();
        return new Result(JSONObject.parse(body));
    }

    @Override
    public Result logout(Map params) {
        return null;
    }

    @Override
    public UserTokenDO getTokenStatus(Map params) {
        return null;
    }

    @Override
    public Result refresh(Map params) {
        return null;
    }

//    @Override
//    public Result getList(Map params) {
//        ResponseEntity<String> exchange = restTemplate.exchange("http://192.168.10.106/cmda/city/getEventPending?type=year", HttpMethod.GET, null, String.class);
//        String body = exchange.getBody();
//        return new Result(JSONObject.parse(body));
//    }

}
